package cn.edu.gues.infosystam.service.impl;

import cn.edu.gues.infosystam.entity.Template;
import cn.edu.gues.infosystam.mapper.TemplateMapper;
import cn.edu.gues.infosystam.service.TemplateService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 苏小小
 * @since 2020-06-11
 */
@Service
public class TemplateServiceImpl extends ServiceImpl<TemplateMapper, Template> implements TemplateService {

    @Override
    public Page<Template> getAllTemplate(Integer tno ,int pageNum, int size) {
        QueryWrapper<Template> queryWrapper = new QueryWrapper<Template>();

        queryWrapper.eq("tno",tno);
        Integer templateTotal = this.baseMapper.selectCount(queryWrapper);
//        System.out.println("模板总数："+templateTotal);

        Page<Template> templatePage = new Page<Template>();
        templatePage.setTotal(templateTotal);
        templatePage.setCurrent(pageNum);
        templatePage.setSize(size);
        templatePage.setPages(templateTotal/size);

        // 将结果封装进页面数据中
        templatePage.setRecords(this.baseMapper.getAllTemplate(pageNum-1, size, tno));


        return templatePage;
    }
}
